package com.mes.cloud.controller;

import com.github.pagehelper.PageInfo;
import com.mes.cloud.dto.BmeBcJoinDTO;
import com.mes.cloud.service.BmeBcJoinService;
import com.mes.cloud.util.CommPager;
import com.mes.cloud.util.JSONResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * <bme_bc_join基础表>
 *
 * @author xhy
 * @version 1.0
 * @date 2019/05/09 16:00
 */
@Api(tags = "BmeBcJoinController", description = "BcJoin配置")
@RestController
@RequestMapping("/bmeBcJoin")
public class BmeBcJoinController {
    private static final Logger LOGGER = LoggerFactory.getLogger(BmeBcJoinController.class);

    @Autowired
    private BmeBcJoinService bmeBcJoinService;

    /**
     * <根据条件获取bme_bc_join基础表列表>
     *
     * @param map
     * @return
     * @author xhy
     * @date 2019/05/09 16:00
     */
    @ApiOperation(value = "列表 无分页")
    @RequestMapping(value = "/findList", method = RequestMethod.POST)
    public JSONResult getBmeBcJoinList(@RequestBody Map<Object, Object> map) {
        LOGGER.info("Class BmeBcJoinController:Method findList :inParam map: " + map.toString());
        JSONResult jsonResult = null;
        try {
            List<BmeBcJoinDTO> bmeBcFiledList = bmeBcJoinService.getBmeBcJoinList(map);
            jsonResult = JSONResult.success(bmeBcFiledList);
        } catch (Exception e) {
            LOGGER.error("Class BmeBcJoinController:Method findList :inParam e: " + e.getMessage());
            jsonResult = JSONResult.fail(201, e.getMessage());
        }
        LOGGER.info("Class BmeBcJoinController:Method findList :OutParam jsonResult: " + jsonResult);
        return jsonResult;
    }

    /**
     * <根据条件获取bme_bc_join基础表分页列表>
     *
     * @param map
     * @return JSONResult
     * @author xhy
     * @date 2019/05/09 16:00
     */
    @ApiOperation(value = "列表 分页")
    @RequestMapping(value = "/findPageList", method = RequestMethod.POST)
    public JSONResult getBmeBcJoinPageList(@RequestBody Map<Object, Object> map) {
        LOGGER.info("Class BmeBcJoinController:Method findPageList :inParam map: " + map.toString());
        JSONResult jsonResult = null;
        try {
            CommPager<BmeBcJoinDTO> pageInfo = bmeBcJoinService.getBmeBcJoinListPage(map);
            jsonResult = JSONResult.success(pageInfo);
        } catch (Exception e) {
            LOGGER.error("Class BmeBcJoinController:Method findPageList :inParam e: " + e.getMessage());
            jsonResult = JSONResult.fail(201, e.getMessage());
        }
        LOGGER.info("Class BmeBcJoinController :Method findPageList :OutParam jsonResult: " + jsonResult);
        return jsonResult;
    }

    /**
     * <获取bme_bc_join基础表的最大记录数>
     *
     * @param map
     * @return JSONResult
     * @author xhy
     * @date 2019/05/09 16:00
     */
    @ApiOperation(value = "获取最大记录数")
    @RequestMapping(value = "/getCount", method = RequestMethod.POST)
    public JSONResult getBmeBcJoinCount(@RequestBody Map<Object, Object> map) {
        LOGGER.info("Class BmeBcJoinController:Method getCount :inParam map: " + map.toString());
        JSONResult jsonResult = null;
        try {
            long count = bmeBcJoinService.getBmeBcJoinCount(map);
            jsonResult = JSONResult.success(count);
        } catch (Exception e) {
            LOGGER.error("Class BmeBcJoinController:Method getCount :inParam e: " + e.getMessage());
            jsonResult = JSONResult.fail(201, e.getMessage());
        }
        LOGGER.info("Class BmeBcJoinController :Method getCount :OutParam jsonResult: " + jsonResult);
        return jsonResult;
    }

    /**
     * <新增bme_bc_join基础表>
     *
     * @param
     * @return JSONResult
     * @author xhy
     * @date 2019/05/09 16:00
     */
    @ApiOperation(value = "新增")
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public JSONResult insertBmeBcJoin(@RequestBody BmeBcJoinDTO bmeBcJoinDTO) {
        LOGGER.info("Class BmeBcJoinController:Method insert :inParam bmeBcJoinDTO: " + bmeBcJoinDTO.toString());
        JSONResult jsonResult = null;
        try {
            long count = bmeBcJoinService.insertBmeBcJoin(bmeBcJoinDTO);
            if (count > 0) {
                jsonResult = JSONResult.success();
            } else {
                jsonResult = JSONResult.fail(201, "操作失败");
            }
        } catch (Exception e) {
            LOGGER.error("Class BmeBcJoinController:Method insert :inParam e: " + e.getMessage());
            jsonResult = JSONResult.fail(201, e.getMessage());
        }
        LOGGER.info("Class BmeBcJoinController :Method insert :OutParam jsonResult: " + jsonResult);
        return jsonResult;
    }

    /**
     * <更新bme_bc_join基础表>
     *
     * @param
     * @return JSONResult
     * @author xhy
     * @date 2019/05/09 16:00
     */
    @ApiOperation(value = "修改")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public JSONResult updateBmeBcJoin(@RequestBody BmeBcJoinDTO bmeBcJoinDTO) {
        LOGGER.info("Class BmeBcJoinController:Method update :inParam bmeBcJoinDTO: " + bmeBcJoinDTO.toString());
        JSONResult jsonResult = null;
        try {
            long count = bmeBcJoinService.updateBmeBcJoin(bmeBcJoinDTO);
            if (count > 0) {
                jsonResult = JSONResult.success();
            } else {
                jsonResult = JSONResult.fail(201, "操作失败");
            }
        } catch (Exception e) {
            LOGGER.error("Class BmeBcJoinController:Method update :inParam e: " + e.getMessage());
            jsonResult = JSONResult.fail(201, e.getMessage());
        }
        LOGGER.info("Class BmeBcJoinController :Method update :OutParam jsonResult: " + jsonResult);
        return jsonResult;
    }

    /**
     * <删除bme_bc_join基础表>
     *
     * @param
     * @return JSONResult
     * @author xhy
     * @date 2019/05/09 16:00
     */
    @ApiOperation(value = "删除")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public JSONResult delBmeBcJoinByPrimaryKey(@RequestBody BmeBcJoinDTO bmeBcJoinDTO) {
        LOGGER.info("Class BmeBcJoinController:Method delete :inParam bmeBcJoinDTO: " + bmeBcJoinDTO);
        JSONResult jsonResult = null;
        try {
            long count = bmeBcJoinService.delBmeBcJoinById(bmeBcJoinDTO.getId());
            if (count > 0) {
                jsonResult = JSONResult.success();
            } else {
                jsonResult = JSONResult.fail(201, "操作失败");
            }
        } catch (Exception e) {
            LOGGER.error("Class BmeBcJoinController:Method delete :inParam e: " + e.getMessage());
            jsonResult = JSONResult.fail(201, e.getMessage());
        }
        LOGGER.info("Class BmeBcJoinController :Method delete :OutParam jsonResult: " + jsonResult);
        return jsonResult;
    }

    /**
     * <根据bme_bc_join基础表标识获取bme_bc_join基础表>
     *
     * @param
     * @return JSONResult
     * @author xhy
     * @date 2019/05/09 16:00
     */
    @ApiOperation(value = "详情")
    @RequestMapping(value = "/get", method = RequestMethod.POST)
    public JSONResult getBmeBcJoinByPrimaryKey(@RequestBody BmeBcJoinDTO bmeBcJoinDTO) {
        LOGGER.info("Class BmeBcJoinController:Method get :inParam bmeBcJoinDTO: " + bmeBcJoinDTO);
        JSONResult jsonResult = null;
        try {
            BmeBcJoinDTO bmeBcJoinDTOs = bmeBcJoinService.getBmeBcJoinById(bmeBcJoinDTO.getId());
            jsonResult = JSONResult.success(bmeBcJoinDTOs);
        } catch (Exception e) {
            LOGGER.error("Class BmeBcJoinController:Method get :inParam e: " + e.getMessage());
            jsonResult = JSONResult.fail(201, e.getMessage());
        }
        LOGGER.info("Class BmeBcJoinController :Method get :OutParam jsonResult: " + jsonResult);
        return jsonResult;
    }

    /**
     * 对Bbme_bc_join基础表标进行批量删除操作
     *
     * @param map
     * @return long
     * @author xhy
     * @date 2019/05/09 16:00
     */
    @ApiOperation(value = "删除 批量")
    @RequestMapping(value = "/batchDelete", method = RequestMethod.POST)
    public JSONResult batchDelete(@RequestBody Map<Object, Object> map) {
        LOGGER.info("Class BmeBcJoinController:Method batchDelete :inParam map: " + map);
        JSONResult jsonResult = null;
        try {
            long count = bmeBcJoinService.batchDelete(map);
            if (count > 0) {
                jsonResult = JSONResult.success();
            } else {
                jsonResult = JSONResult.fail(201, "操作失败");
            }
        } catch (Exception e) {
            LOGGER.error("Class BmeBcJoinController:Method batchDelete :inParam e: " + e.getMessage());
            jsonResult = JSONResult.fail(201, e.getMessage());
        }
        LOGGER.info("Class BmeBcJoinController :Method batchDelete :OutParam jsonResult: " + jsonResult);
        return jsonResult;
    }

    /**
     * 对bme_bc_join是否启用
     *
     * @param map
     * @return long
     * @author xhy
     * @date 2019/05/09 16:00
     */
    @ApiOperation(value = "启用禁用")
    @RequestMapping(value = "/enable", method = RequestMethod.POST)
    public JSONResult enable(@RequestBody Map<Object, Object> map) {
        LOGGER.info("Class BmeBcJoinController:Method updateEnable :inParam map: " + map);
        JSONResult jsonResult = null;
        try {
            long count = bmeBcJoinService.enable(map);
            if (count > 0) {
                jsonResult = JSONResult.success();
            } else {
                jsonResult = JSONResult.fail(201, "操作失败");
            }
        } catch (Exception e) {
            LOGGER.error("Class BmeBcJoinController:Method updateEnable :inParam e: " + e.getMessage());
            jsonResult = JSONResult.fail(201, e.getMessage());
        }
        LOGGER.info("Class BmeBcJoinController :Method updateEnable :OutParam jsonResult: " + jsonResult);
        return jsonResult;
    }

    /**
     * 启用停用 批量
     *
     * @param map
     * @return com.mes.cloud.util.JSONResult
     */
    @ApiOperation(value = "启用停用 批量")
    @RequestMapping(value = "/batchEnable", method = RequestMethod.POST)
    public JSONResult batchEnable(@RequestBody Map<Object, Object> map) {
        JSONResult result = new JSONResult();
        try {
            bmeBcJoinService.batchEnable(map);
            result = JSONResult.success();
        } catch (Exception e) {
            LOGGER.error("Class BmeBcJoinController:Method updateEnable :inParam e: " + e.getMessage());
            result = JSONResult.fail(201, e.getMessage());
        }
        LOGGER.info("Class BmeBcJoinController :Method updateEnable :OutParam jsonResult: " + result);
        return result;
    }

    @ApiOperation(value = "导出")
    @RequestMapping(value = "/exportFile", method = RequestMethod.GET)
    public JSONResult exportFile(@RequestParam Map<Object, Object> map, HttpServletResponse response) {
        JSONResult result;
        try {
            bmeBcJoinService.exportFile(map, response);
            result = JSONResult.success();
        } catch (Exception e) {
            LOGGER.error(e.getMessage());
            result = JSONResult.fail(201, e.getMessage());
        }
        return result;
    }

    @ApiOperation(value = "导入")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public JSONResult importExcel(@RequestParam MultipartFile file) {
        JSONResult result;
        try {
            result = JSONResult.success(bmeBcJoinService.importExcel(file));
        } catch (Exception e) {
            LOGGER.error(e.getMessage());
            result = JSONResult.fail(201, e.getMessage());
        }
        return result;
    }
}
